package org.clipjoint.dao.impl;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.clipjoint.dao.EventDao;
import org.clipjoint.entity.Event;
import org.clipjoint.util.DataSourceUtil;

import java.sql.SQLException;
import java.util.List;

public class EventDaoImpl implements EventDao {


    @Override
    public List<Event> showAll() throws SQLException {
        // 创建DButils核心对象
        QueryRunner qr = new QueryRunner(DataSourceUtil.getDataSource());

        // 编写sql语句
        String sql = "SELECT `name`,`image` FROM `event`";

        // 执行sql
        List<Event> result = qr.query(sql, new BeanListHandler<>(Event.class));

        return result;
    }
}
